package situ.autoweter.service.impl;
import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import situ.autoweter.service.UsUserService;
import situ.autoweter.dao.UsUserDao;
import situ.autoweter.common.Assist;
import situ.autoweter.entity.UsUser;
import java.util.*;
/**
 * UsUser的服务接口的实现类
 * 
 * @author 
 *
 */
@Service
public class UsUserServiceImpl implements UsUserService {
	private final Logger LOG = LogManager.getLogger(this.getClass());

	@Autowired
	private UsUserDao usUserDao;
	// TODO 当你看到这个方法时你应该创建一个工具类做通用的方法,定义自己的返回格式化
	private static final int C200 = 200;
	private static final int C412 = 412;
	public String resultFormat(int code, Object data) {
		JSONObject result = new JSONObject();
		result.put("code", code);
		if (data != null) {
			result.put("data", data);
		}
		return result.toJSONString();
	}

	@Override
	public List<UsUser> find(UsUser value) {
		//TODO这里可以做通过Assist做添加查询
		List<UsUser> result = usUserDao.selectUsUser(null);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行获取UsUser数据集-->结果:", result);
		}
		return result;
	}
	@Override
	public UsUser findOne(String id) {
		if (id == null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行通过UsUser的id获得UsUser对象-->失败:id不能为空");
			}
			return null;
		}
		UsUser result = usUserDao.selectUsUserById(id);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行通过UsUser的id获得UsUser对象-->结果:", result);
		}
		return result;
	}

	@Override
	public String saveNotNull(UsUser value) {
		if (value == null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行将UsUser中属性值不为null的数据保存到数据库-->失败:对象不能为空");
			}
			return resultFormat(C412, null);
		}
		int result = usUserDao.insertNotNullUsUser(value);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行将UsUser中属性值不为null的数据保存到数据库-->结果:", result);
		}
		return resultFormat(C200, result);
	}
	@Override
	public String updateNotNullById(UsUser value) {
		if (value == null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行通过UsUser的id更新UsUser中属性不为null的数据-->失败:对象为null");
			}
			return resultFormat(C412, null);
		}
		int result = usUserDao.updateNotNullUsUserById(value);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行通过UsUser的id更新UsUser中属性不为null的数据-->结果:", result);
		}
		return resultFormat(C200, result);
	}

	@Override
	public String deleteById(String id) {
		if (id == null) {
			if (LOG.isDebugEnabled()) {
				LOG.debug("执行通过UsUser的id删除UsUser-->失败:id不能为空");
			}
			return resultFormat(C412, null);
		}
		int result = usUserDao.deleteUsUserById(id);
		if (LOG.isDebugEnabled()) {
			LOG.debug("执行通过UsUser的id删除UsUser-->结果:", result);
		}
		return resultFormat(C200, result);
	}

	@Override
	public UsUser UserMoneys() {
		return usUserDao.UserMoneys();
	}

	@Override
	public List<Map> QueryByMoney(Integer number) {
		return usUserDao.QueryByMoney(number);
	}


	@Override
	public List<Map> query(Integer start,Integer count,Integer volumeid) {
		return usUserDao.query(start,count,volumeid);
	}

	/**
	 *查詢數據條數
	 * @return 數據縂條數
	 * */
	@Override
	public int pageCount(Integer volumeid) {

		return usUserDao.pageCount(volumeid);
	}





}